#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <cerrno>
#include <cstring>
#include <cassert>
#include <unistd.h>
#include "comm.hpp"

int main()
{
    int wfd = open(filename.c_str(), O_WRONLY);
    if (wfd < 0)
    {
        std::cout << errno << ": " << strerror(errno) << std::endl;
        return 1;
    }

    char buffer[NUM];
    while (true)
    {
        std::cout << "请输入你的消息# ";
        char* msg = fgets(buffer, sizeof(buffer) - 1, stdin);
        assert(msg);
        (void)msg;

        // system("stty raw");
        // int c = getchar();
        // system("stty -raw");

        buffer[strlen(buffer) - 1] = 0;
        if (strcasecmp(buffer, "quit") == 0) break;

        ssize_t n = write(wfd, buffer, strlen(buffer));
        assert(n >= 0);
        (void)n;
    }

    close(wfd);
}